{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# PyTorch练习1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请输出你的姓名\n",
    "print('范煜')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用tensor编写并训练一个感知器模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.9.0\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "print(torch.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#生成训练数据\n",
    "def GenerateSamples(n):\n",
    "    x1 = torch.randn((2,n)) + 2\n",
    "    x2 = torch.randn((2,n)) - 2\n",
    "    y1 = torch.ones((n))\n",
    "    y2 = torch.zeros((n))\n",
    "    x = torch.cat((x1,x2),dim = 1)\n",
    "    y = torch.cat((y1,y2),dim = 0)\n",
    "    \n",
    "    return x,y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([2, 60])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,\n",
       "        1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.,\n",
       "        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
       "        0., 0., 0., 0., 0., 0.])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAA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caOkhyT9ReZ6JnlM0vURcYOk70q6L3M94zwn6YOSvp67kFFs75b0GUm/K+k6SX9k+7q8VY30D5IO5C5iRm9KuicirpP0Hkl/1tJz+r+SbouIX5d0o6QDtt+Tt6TxWhHkkj4l6V5JrZ15jYj/2fLhL6jdtT4aEW8OPvyGqhtjt05EnIyIF3PXMcHNkl6KiO9FxBuSHpR0Z+aaLhIRX5f049x1zCIivh8RTw/e/6mkk5KuzlvVxaLy+uDDSwdvrf0/nz3Ibd8p6dWIeDZ3LdPYPmb7ZUmraveIfKuPSvpa7iIKdbWkl7d8/IpaGDqlsr0s6d2Svpm5lJFs77b9jKTXJD0WEa2sU1rQHYJsPy7pyhGfOizpk6raKtlNqjMivhIRhyUdtn2fpLskHVlogVtMq3XwNYdVvZRdX2RtW81SJ/rH9uWSvijp49te7bZGRLwl6cbBHNOXbV8fEa2ch1hIkEfEe0c9bvtdkq6V9KxtqWoBPG375oj4wSJq22pcnSOsS3pYGYN8Wq22PyLpDkm/HRkvFpjjnLbRq5L2b/n4msFjqMH2papCfD0ivpS7nmki4ie2n1A1D9HKIM/aWomIb0fE2yNiOSKWVb10/Y0cIT6N7Xdu+fBOSd/JVcs0tg+omnN4f0SczV1PwZ6S9E7b19q+TNKHJH01c01FczVi+ztJJyPir3PXM47tfcPVXrZ/XtL71OL/89l75AX5K9vP2f6WqlZQK5dNDXxa0hWSHhssl/xc7oJGsf0B269I+k1J/2z7kdw1bTWYML5L0iOqJuW+EBHP563qYrb/SdK/S/o126/Y/tPcNU1wi6QPS7pt8G/zGdu35y5qhKskPTH4//6Uqh75Q5lrGotL9AGgcIzIAaBwBDkAFI4gB4DCEeQAUDiCHAAKR5ADQOEIcgAo3P8BRQlCLWEyt+IAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "X,Y = GenerateSamples(30)\n",
    "print(X.shape)\n",
    "plt.plot(X[0,Y==1],X[1,Y==1],'r+')\n",
    "plt.plot(X[0,Y==0],X[1,Y==0],'bo')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "#编写模型并训练\n",
    "def sign(y):\n",
    "    if y >0 :\n",
    "        return 1\n",
    "    return 0\n",
    "w = torch.randn(2)\n",
    "b = torch.randn(1)[0]\n",
    "X =  X.transpose(1,0)\n",
    "lr = 0.02\n",
    "epoch = 60\n",
    "for i in range(epoch):\n",
    "    if sign(w@X[i] +b) != Y[i]:\n",
    "        w+=lr*X[i]*(1 if Y[i] == 1 else -1)\n",
    "        b +=lr*(1 if Y[i]==1 else -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1677d2947c0>]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAAADxeG0DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAXMElEQVR4nO3dfYxddZ3H8c932kIpCAU6gPZhWqSlD1ORMLJk0eAKiyxPPhO0iERJJdEEEjeubmM6GPkDTVz/0EQbswmmk7ibCHFDuj4FdbN/uHGqCJ0WaKlUWnkYnspDoTjtd//4zeXch7kzd+ace8/5nfN+JZPO3J459zcX+pnf/f6+v3PM3QUAiFdf3gMAAKRDkANA5AhyAIgcQQ4AkSPIASBy8/N40iVLlvjKlSvzeGoAiNbOnTufc/f+5sdzCfKVK1dqdHQ0j6cGgGiZ2YGpHqe0AgCRI8gBIHIEOQBEjiAHgMgR5AAQOYIcQPaGh/MeQaUQ5ACyd+edeY+gUghyAIgcQQ4gG8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"<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#测试模型\n",
    "X,Y = GenerateSamples(30)\n",
    "xx = np.arange(-5,5)\n",
    "yy = (w[0]*xx-b)/w[1]\n",
    "plt.plot(xx,yy,'r')\n",
    "plt.plot(X[0,Y==1],X[1,Y==1],'r+')\n",
    "plt.plot(X[0,Y==0],X[1,Y==0],'bo')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([60, 2])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.transpose(1,0).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
